package demo1;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-07-17
 * Time: 9:16
 */
public class Test {
    public static void main(String[] args) {
        BigDecimal num1 = new BigDecimal("1.23");
        BigDecimal num2 = new BigDecimal("2.34");
        BigDecimal num3 = num1.divide(num2,3, RoundingMode.HALF_UP);
        BigDecimal num4 = num1.divide(num2,new MathContext(4,RoundingMode.HALF_UP));
        System.out.println(num3);
        System.out.println(num4);
    }
    public static void main6(String[] args) {
        BigDecimal num1 = new BigDecimal("1.23");
        BigDecimal num2 = new BigDecimal("2.34");
        BigDecimal num3 = num1.add(num2);
        System.out.println(num3);
        BigDecimal num4 = num1.subtract(num2);
        System.out.println(num4);
        BigDecimal num5 = num1.multiply(num2);
        System.out.println(num5);
    }
    public static void main5(String[] args) {
        BigDecimal num1 = new BigDecimal(1);
        System.out.println(num1);
        BigDecimal num2 = new BigDecimal(1.23);
        System.out.println(num2);
        BigDecimal num3 = new BigDecimal(1.23F);
        System.out.println(num3);
        BigDecimal num4 = new BigDecimal("1.23");
        System.out.println(num4);
    }
    public static void main4(String[] args) {
        LocalDateTime nowDate = LocalDateTime.now();
        LocalDateTime firstDate = nowDate.with(TemporalAdjusters.firstDayOfMonth());
        System.out.println("当前日期所在月的第一天："+ firstDate);
        LocalDateTime lastDate = nowDate.with(TemporalAdjusters.lastDayOfMonth());
        System.out.println("当前日期所在月的最后一天："+ lastDate);
    }
    public static void main3(String[] args) {
        LocalDateTime nowDate = LocalDateTime.now();
        //获取当前日期所在周的周一
        LocalDateTime firstDate = nowDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
        //获取当前日期所在周的周日
        LocalDateTime lastDate = nowDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
        System.out.println(firstDate);
        System.out.println(lastDate);
    }
    public static void main2(String[] args) {
        LocalDateTime nowDate = LocalDateTime.now();
        LocalDateTime datePlus = nowDate.plusDays(1);
        System.out.println("增加一天后的日期"+ datePlus);
        LocalDateTime dateMinus = nowDate.minusDays(1);
        System.out.println("减少一天后的日期"+ dateMinus);
    }
    public static void main1(String[] args) {
        LocalDateTime nowDate = LocalDateTime.now();
        System.out.println("当前日期："+nowDate);
        System.out.println("本周的第几天："+ nowDate.getDayOfWeek().getValue());
        System.out.println("本月的第几天："+ nowDate.getDayOfMonth());
        System.out.println("本年的第几天："+ nowDate.getDayOfYear());
    }
}
